/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.approval.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.biz.modular.approval.entity.BizApproval;
import vip.xiaonuo.biz.modular.approval.entity.BizSummarization;
import vip.xiaonuo.biz.modular.approval.param.*;
import vip.xiaonuo.biz.modular.approval.result.BizApprovalOrderCanteenStatisticsResult;
import vip.xiaonuo.biz.modular.approval.service.BizApprovalService;
import vip.xiaonuo.biz.modular.approvalorder.result.BizApprovalCanteenUserResult;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

import java.util.List;

/**
 * 审批管理控制器
 *
 * @author fqa
 * @date 2025/05/09 18:20
 */
@Tag(name = "审批管理控制器")
@RestController
@Validated
public class BizApprovalController {

    @Resource
    private BizApprovalService bizApprovalService;


    /**
     * 获取审批管理分页
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "获取审批管理分页")
    @SaCheckPermission("/biz/approval/page")
    @GetMapping("/biz/approval/page")
    public CommonResult<Page<BizApproval>> page(BizApprovalPageParam bizApprovalPageParam) {
        return CommonResult.data(bizApprovalService.page(bizApprovalPageParam));
    }

    /**
     * 获取审批管理分页
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "获取审批管理分页")
    @SaCheckPermission("/biz/approval/waring")
    @GetMapping("/biz/approval/waring")
    public CommonResult<Page<BizApproval>> waring(BizApprovalWaringParam bizApprovalPageParam) {
        return CommonResult.data(bizApprovalService.waring(bizApprovalPageParam));
    }

    /**
     * 添加审批管理
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "添加审批管理")
    @CommonLog("添加审批管理")
    @SaCheckPermission("/biz/approval/add")
    @PostMapping("/biz/approval/add")
    public CommonResult<String> add(@RequestBody @Valid BizApprovalAddParam bizApprovalAddParam) {
        bizApprovalService.add(bizApprovalAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑审批管理
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "编辑审批管理")
    @CommonLog("编辑审批管理")
    @SaCheckPermission("/biz/approval/edit")
    @PostMapping("/biz/approval/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizApprovalEditParam bizApprovalEditParam) {
        bizApprovalService.edit(bizApprovalEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除审批管理
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "删除审批管理")
    @CommonLog("删除审批管理")
    @SaCheckPermission("/biz/approval/delete")
    @PostMapping("/biz/approval/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                       List<BizApprovalIdParam> bizApprovalIdParamList) {
        bizApprovalService.delete(bizApprovalIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取审批管理详情
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "获取审批管理详情")
    @GetMapping("/biz/approval/detail")
    public CommonResult<BizApproval> detail(@Valid BizApprovalIdParam bizApprovalIdParam) {
        return CommonResult.data(bizApprovalService.detail(bizApprovalIdParam));
    }


    /**
     * mp创建审批
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "mp创建审批")
    @CommonLog("创建审批")
    @PostMapping("/biz/approval/createApproval")
    public CommonResult<String> createApproval(@RequestBody @Valid BizApprovalCreateParam bizApprovalCreateParam) {
        bizApprovalService.createApproval(bizApprovalCreateParam);
        return CommonResult.ok();
    }


    /**
     * 审批进度
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "审批进度")
    @GetMapping("/biz/approval/approvalPage")
    public CommonResult<Page<BizApproval>> approvalPage(BizUserApprovalPageParam bizApprovalPageParam) {
        return CommonResult.data(bizApprovalService.approvalPage(bizApprovalPageParam));
    }


    /**
     * 处理审批分页
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "处理审批分页")
    @SaCheckPermission("/biz/approval/disposeApprovalPage")
    @GetMapping("/biz/approval/disposeApprovalPage")
    public CommonResult<Page<BizApproval>> disposeApprovalPage(BizDisposeApprovalPageParam bizApprovalPageParam) {
        return CommonResult.data(bizApprovalService.disposeApprovalPage(bizApprovalPageParam));
    }

    /**
     * mp审批操作
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "mp审批操作")
    @SaCheckPermission("/biz/approval/approvalOperate")
    @PostMapping("/biz/approval/approvalOperate")
    public CommonResult<String> approvalOperate(@RequestBody @Valid BizApprovalOperateParam bizApprovalOperateParam) {
        bizApprovalService.approvalOperate(bizApprovalOperateParam);
        return CommonResult.ok();
    }


    /**
     * 撤回审批
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "撤回审批")
    @PostMapping("/biz/approval/recallApproval")
    public CommonResult<String> recallApproval(@RequestBody @Valid BizApprovalIdParam bizApprovalIdParam) {
        bizApprovalService.recallApproval(bizApprovalIdParam);
        return CommonResult.ok();
    }

    /**
     * 获取食堂审批统计
     *
     * @author fqa
     * @date 2025/05/09 18:20
     */
    @Operation(summary = "获取食堂审批统计")
    @PostMapping("/biz/approval/canteenStatisticsList")
    public CommonResult<List<BizApprovalOrderCanteenStatisticsResult>> canteenStatisticsList() {
        return CommonResult.data(bizApprovalService.canteenStatisticsList());
    }


    /**
     * 审批统计
     *
     * @return 审批统计
     */
    @Operation(summary = "审批统计")
    @SaCheckPermission("/biz/approval/summarizationList")
    @PostMapping("/biz/approval/summarizationList")
    public CommonResult<List<BizSummarization>> summarizationList() {
        return CommonResult.data(bizApprovalService.summarizationList());
    }

    /**
     * 获取用户食堂统计
     *
     * @return 获取用户食堂统计
     */
    @Operation(summary = "获取用户食堂统计")
    @SaCheckPermission("/biz/approval/getBizApprovalCanteenUserResult")
    @PostMapping("/biz/approval/getBizApprovalCanteenUserResult")
    public CommonResult<List<BizApprovalCanteenUserResult>> getBizApprovalCanteenUserResult(String date) {
        return CommonResult.data(bizApprovalService.getBizApprovalCanteenUserResult(date));
    }


}
